const express = require('express');
const router = express.Router();//路由器
const path=require('path');
const HfController=require('../controllers/hfController.js');

/* 完成图片上传功能 */
const multer=require('multer');
// const upload=multer({desk:path.join(__dirname,'../public/uploads')})
const storage=multer.diskStorage({
    destination:function (req,file,cb) {
        cb(null,path.join(__dirname,'../public/uploads'))
    },
    filename:function (req,file,cb) {
        const uniqueSuffix=Date.now()+'-'+Math.round(Math
            .random()*1E9);
        // path.extname(file.originalname) 可以获取文件的扩展名
        cb(null,file.fieldname+'-'+uniqueSuffix+path.extname(file.originalname));
    }
})
const upload=multer({storage:storage});

//入库
router.post('/store',upload.fields([{name:'banner'},{name:'logo'}]),HfController.AddInfoPutInStore);
//头部尾部信息的展示
router.get('/hf',HfController.showInfo);

module.exports = router;